package com.nlx.notes.module.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nlx.notes.module.bean.vo.category.IconMaterialVO;
import com.nlx.notes.module.core.consts.GlobalConst;
import com.nlx.notes.module.core.util.DataConvertorUtils;
import com.nlx.notes.module.entity.IconMaterial;
import com.nlx.notes.module.mapper.IconMaterialMapper;
import com.nlx.notes.module.service.IIconMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author nlx
 * @since 2025-08-30
 */
@Service
public class IconMaterialServiceImpl extends ServiceImpl<IconMaterialMapper, IconMaterial> implements IIconMaterialService {

    @Override
    public List<IconMaterial> findByIconIds(List<Long> iconIds) {
        if(CollUtil.isEmpty(iconIds)){
            return null;
        }
        return this.getBaseMapper().selectList(Wrappers.lambdaQuery(IconMaterial.class)
                .in(IconMaterial::getId,iconIds)
                .eq(IconMaterial::getDelFlag, GlobalConst.DEL_FLAG_NORMAL));
    }

    @Override
    public List<IconMaterialVO> iconList(String iconType) {
        if(StrUtil.isEmpty(iconType)){
            return CollUtil.newArrayList();
        }
        List<IconMaterial> iconMaterialList = this.getBaseMapper().selectList(Wrappers.lambdaQuery(IconMaterial.class)
                .eq(IconMaterial::getIconType, iconType)
                .eq(IconMaterial::getDelFlag, GlobalConst.DEL_FLAG_NORMAL));
        if(CollUtil.isNotEmpty(iconMaterialList)){
            return DataConvertorUtils.copyListProperties(iconMaterialList,IconMaterialVO::new);
        }
        return CollUtil.newArrayList();
    }
}
